package charpter11.lynx;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;

public class TwentyThree {
	public static void main(String[] args) {
	    Random rand = new Random(47);
	    Map<Integer,Integer> m =
	      new HashMap<Integer,Integer>();
	    for(int i = 0; i < 10000; i++) {
	      // Produce a number between 0 and 20:
	      int r = rand.nextInt(20);
	      Integer freq = m.get(r);
	      m.put(r, freq == null ? 1 : freq + 1);
	    }
	    boolean first = true;
	    int max = 0;
	    int key = 0;
	    for (Entry<Integer, Integer> entry : m.entrySet()){
	    	if (first){
	    		max = entry.getValue();
	    	}else{
	    		max = max < entry.getValue()?entry.getValue():max;
	    		key = max < entry.getValue()?entry.getKey():key;
	    	}
	    }
	    System.out.println(key + ":" + max);
	  }
}
